USE [PeDALS_DEV]
GO

/****** Object:  StoredProcedure [dbo].[PAC_UpdateIngested]    Script Date: 10/21/2009 14:06:34 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PAC_UpdateIngested]
	@AcqId INT,
	@Ingested VARCHAR(12)
AS
BEGIN
	TRY
	SET NOCOUNT ON
	BEGIN TRANSACTION

		--Get ingested value in database to see if any change was made to value
		DECLARE @currentIngested VARCHAR(12)
		SET @currentIngested = (SELECT SeriesAcquisitionIngested FROM SeriesAcquisition WHERE SeriesAcquisitionId = @AcqId)
		IF @currentIngested IS NULL
		BEGIN
		SET @currentIngested = ''
		END
		IF (RTRIM(LTRIM(@Ingested)) <> RTRIM(LTRIM(@currentIngested)))	
		BEGIN
			UPDATE SeriesAcquisition
			SET SeriesAcquisitionIngested = LTRIM(RTRIM(@Ingested)),			
				ModifiedDate = GetDate(),
				ModifiedBy = 'Cataloger'
			WHERE SeriesAcquisitionId = @AcqId
	END
	COMMIT TRANSACTION
END TRY
BEGIN CATCH
      ROLLBACK TRANSACTION
		PRINT 'An error occurred.  Please notify your administrator to check the error database.'
		INSERT INTO [PEDALS_PAC_ERRORS].[dbo].[PAC_ERROR](ErrorNumber, ErrorMessage, CreatedDate)
			VALUES (ERROR_NUMBER(), ERROR_MESSAGE(), GETDATE())
END CATCH

GO


